﻿#include "InstructionWait.h"

#include "ScriptRunner.h"

__SCRIPTINSTRUCTION_REGISTER(InstructionWait,ScriptInstruction::MetaInstruction_Wait,&InstructionWait::fromByteArray1);

InstructionWait::InstructionWait()
{
  instructionFlag = MetaInstruction_Wait;
}

InstructionWait::InstructionWait(InstructionWait const & instructionWait)
{
  *this=instructionWait;
}

InstructionWait& InstructionWait::operator=(InstructionWait const& instructionWait)
{
  *(ScriptInstruction*)this=instructionWait;
  interval=instructionWait.interval;
  return *this;
}

InstructionWait::~InstructionWait()
{}

void InstructionWait::run()
{
  scriptRunner->scriptWaitAndRun(interval,deviceId);
}

QString InstructionWait::toString()
{
  return QStringLiteral("等待，时间：%1s").arg(interval/1000);
}

QByteArray InstructionWait::toByteArray()
{
  return ScriptInstruction::toByteArray().append((char*)&interval,sizeof (interval));
}

ScriptInstruction *InstructionWait::fromByteArray1(char * const src,int size,int * offset)
{
  if((size-*offset)<byteArraySize)
    {
      return Q_NULLPTR;
    }
  InstructionWait* instructionWait=new InstructionWait();
  instructionWait->setInterval(*(int*)(src+*offset));
  *offset+=sizeof (interval);
  return instructionWait;
}

int InstructionWait::getInterval()
{
  return interval;
}

InstructionWait* InstructionWait::setInterval(int interval)
{
  this->interval=interval;
  return this;
}
